package com.wiwl.web.controller;

import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.wiwl.domain.ObjetoPersistente;
import com.wiwl.security.Role;

/**
 * 
 *
 * @author gaston.dubra
 */
@Entity
public class MenuItem extends ObjetoPersistente{

  @Basic
  private String description;
  @Basic
  private String url;
  @ManyToMany
  @Cascade(value={CascadeType.DELETE_ORPHAN,CascadeType.PERSIST})
  @JoinTable(
       name="MENU_ROLE",
       joinColumns=@JoinColumn(name="MENU_ID"),
       inverseJoinColumns=@JoinColumn(name="ROLE_ID"))
  private List<Role> roles;
  @ManyToOne(targetEntity=MenuItem.class)
  @JoinColumn(name="PARENT_ID")
  private MenuItem parentMenuItem;
  @OneToMany(mappedBy="parentMenuItem", targetEntity=MenuItem.class)
  @Cascade(value={CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.PERSIST})
  private List<MenuItem> childMenuitems;
  
  public String getDescription() {
    return description;
  }
  public void setDescription(String description) {
    this.description = description;
  }
  public String getUrl() {
    return url;
  }
  public void setUrl(String url) {
    this.url = url;
  }
  
  public MenuItem getParentMenuItem() {
    return parentMenuItem;
  }
  public void setParentMenuItem(MenuItem parentMenuItem) {
    this.parentMenuItem = parentMenuItem;
  }
  public List<Role> getRoles() {
    return roles;
  }
  public void setRoles(List<Role> roles) {
    this.roles = roles;
  }
  public List<MenuItem> getChildMenuitems() {
    return childMenuitems;
  }
  public void setChildMenuitems(List<MenuItem> childMenuitems) {
    this.childMenuitems = childMenuitems;
  }
  
}
